package com.jinyijia.api.rest.v1.brand;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author yangrd
 * @date 2018/8/8
 * 接口4
 **/
@RestController
@RequestMapping("/brands")
public class BrandController {

    private RestTemplate restTemplate;

    @Autowired
    public BrandController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @GetMapping
    public List<BrandVO> list(Integer categoryId) {
        return restTemplate.exchange("http://brand-service/brands/cids?cid=" + categoryId, HttpMethod.GET, null, new ParameterizedTypeReference<List<BrandVO>>() {
        }).getBody();
    }

    @GetMapping("/all")
    public List<BrandVO> all(){
        return restTemplate.exchange("http://brand-service/brands",HttpMethod.GET,null,new ParameterizedTypeReference<List<BrandVO>>(){}).getBody();
    }
}
